
<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
    <title>两点间距离</title>
    <link rel="stylesheet" href="https://a.amap.com/jsapi_demos/static/demo-center/css/demo-center.css"/>
    <style>
        html, body, #container {
            height: 100%;
        }

        .amap-icon img {
            width: 25px;
            height: 34px;
        }

        .amap-marker-label {
            border: 0;
            background-color: transparent;
        }

        .info {
            position: relative;
            top: -6px;
            right: 23px;
            min-width: 0;
            border-radius: 1.25rem;
            background-color: transparent;
            color: #FFFFFF;
            font-size: 18px;
            margin: 0;
        }

        .info2 {
            top: -100px;
            left: 10px;
            color: #FF0000;
            width: 200px;
            height: 100px;
            margin: 0;
            float: left;

        }

        .info3 {
            top: -100px;
            right: 10px;
            float: left;
            margin-left: 8%;
        }

        .amap-scale-text {
            font-size: 15px;
        }

    </style>
</head>
<body>
<div id="container"></div>
<div class="info info2"><h3>25</h3></div>
<div class="info info2 info3"><h3>备注1</h3></div>
<div class="info info2 info3"><h3>备注2</h3></div>
<script type="text/javascript"
        src="https://webapi.amap.com/maps?v=1.4.13&key=df544bf0a08551ba7e69e86133c40377"></script>
<script type="text/javascript">
    //初始化地图对象，加载地图
    var map = new AMap.Map("container", {
        resizeEnable: true,
        layers: [new AMap.TileLayer.Satellite()],
        zoom: 10
    });

    //设置点的信息
    var markers = {{ my_data|safe }};

    //点打标记
    markers.forEach(function (each_point) {
        var mark = new AMap.Marker({
            map: map,
            draggable: true,
            position: each_point.position_,
            offset: new AMap.Pixel(-13, -30)

        });
        mark.setLabel({
            //修改label相对于maker的位置
            offset: new AMap.Pixel(20, 20),
            content: "<div class='info'><b>"+each_point.content+"</b></div>"
        });

    });
    //视图位置优化


    map.setFitView();


    var line;
    var path = [];

    for (var j = 1, i = 0; i < markers.length - 1; i++) {
        name_1 = markers[i].position_;
        j = i + 1;
        if (j < markers.length) {
            name_2 = markers[j].position_;
        }

        path.push({'path_line': [name_1, name_2]});

    }

    function computeDis() {

        path.forEach(function (path_each) {
            //线的规格
            line = new AMap.Polyline({
                map: map,
                strokeColor: 'red',
                strokeWeight: 5,
                isOutline: true,
                outlineColor: 'white',
                path: path_each.path_line
            });
            line.setPath(path_each.path_line);

        })

    }

    //设置标尺
    map.plugin(["AMap.Scale"], function () {
        var scale = new AMap.Scale();

        map.addControl(scale);
    });
    computeDis();





</script>

</body>
</html>